/////////////////////////////////////////////////
repo:    comment_driven
target:  comment_driven
branch:  6.x-1.x
tags:    6.x-1.0-unstable-6 6.x-1.x-dev
node:    4bd09b09f6a89eefd08a6d94bce6161e16a8a6e8
changes:
* support [#739690]: comment_upload at the expense of having NO comment preview
* wrong varname & missing return => node_form not being saved
/////////////////////////////////////////////////
=================================================
message: support [#739690]: comment_upload at the expense of having NO comment preview
branch:  6.x-1.x
tags:    
node:    c00df3de5b46371a0f42d2b4b2c7dfbaf73270f6
=================================================
diff -r 4bd09b09f6a8 -r c00df3de5b46 comment_driven/comment_driven.module
--- comment_driven.module	Sat Mar 13 16:19:56 2010 -0500
+++ comment_driven.module	Sat Mar 13 21:22:47 2010 -0500
@@ -120,13 +120,9 @@ function comment_driven_form_node_type_f
     '#description' => t('Whether this content type will be driven through comments.'),
     '#default_value' => variable_get($varname . '_' . $node_type, 0),
   );
-  // incompatible with comment_upload [#741544-8]
-  $active_comment_upload = variable_get('comment_upload_' . $node_type, 0);
-  if ($active_comment_upload) {
-    $form['comment_driven'][$varname]['#default_value'] = 0;
-    $form['comment_driven'][$varname]['#disabled'] = TRUE;
-    $form['comment_driven'][$varname]['#description'] .= '<br/>' . t('Regretfully driven properties are !incompatible, you can disable "attachments on comments" to enable driven properties for this content type.', array('!incompatible' => l(t('incompatible with comment_upload'), 'http://drupal.org/node/741544#comment-2715990')));
-  }
+  // incompatibility with comment_upload [#741544-8]
+  // can't allow driven properties, "attachments on comments" and preview at the same time
+  $form['#submit'][] = 'comment_driven_node_type_submit';
   
   $varname = 'comment_driven:exclusivity';
   $form['comment_driven'][$varname] = array(
@@ -257,6 +253,17 @@ function comment_driven_form_node_type_f
   );
 }
 
+function comment_driven_node_type_submit($form, &$form_state) {
+  $values = $form_state['values'];
+  // incompatibility with comment_upload [#741544-8]
+  // can't allow driven properties, "attachments on comments" and preview at the same time
+  if ($values['comment_driven:enabled'] && $values['comment_upload'] && $values['comment_preview'] !== COMMENT_DRIVEN__PREVIEW_DISABLED) {
+    drupal_set_message(t('Note that "comment preview" won\'t be available due to an !issue.', array('!issue' => l(t('incompatibility issue'), 'http://drupal.org/node/741544#comment-2715990')))
+      . ' ' . t('If you prefer having it, you will need to disable "driven properties" or "attachments on comments", since having them both is what prevents "comment preview" from working.'),
+      'warning');
+  }
+}
+
 /**
  * Implementation of hook_node_type().
  */
@@ -448,6 +455,9 @@ function comment_driven_form_alter(&$for
       
       // don't unset $form_state['node'] for node_form processing (don't know if it will be needed)
       $ned_form_state = $form_state; // needed to preserve values (e.g. taxonomy)
+      // currently preview isn't supported if comment_upload is providing "attachments on comments" [#741544-8]
+      // but (in the future) other modules might receive "exclude from disguise" treatment
+      $ned_form_state['values'] = _comment_driven_extract_node_state_values($ned_form_state['values']);
       
       // restore comment's previewed values
       $previewed = $form_state['comment_driven:preview']['comment'];
@@ -507,8 +517,15 @@ function comment_driven_form_alter(&$for
     // since it relies in comment_form not being cached 
     // instead we'll follow node_form approach
     $form['submit']['#submit'] = $form['#submit'];
-    $form['preview']['#type'] = 'submit'; // no longer a button
-    $form['preview']['#submit'] = array('comment_driven_build_preview');
+    // incompatibility with comment_upload [#741544-8]
+    // can't allow "driven properties", "attachments on comments" and "comment preview" at the same time
+    if (variable_get('comment_upload_' . $node_type, 0)) {
+      unset($form['preview']);
+    }
+    else {
+      $form['preview']['#type'] = 'submit'; // no longer a button
+      $form['preview']['#submit'] = array('comment_driven_build_preview');
+    }
     
     // these properties doesn't mean anything to an element
     $form_level_keys = array(
@@ -519,7 +536,7 @@ function comment_driven_form_alter(&$for
     // prepare to merge node_form into comment_form
     // avoid name clashes
     // (e.g. 'comment' is the body in comment_form and the comment_settings in node_form)
-    $keys = array_diff(element_children($form), $form_level_keys);
+    $keys = array_diff(element_children($form), array_merge($form_level_keys, _comment_driven_disguise_exceptions()));
     foreach ($keys as $key) {
       $form['comment_driven'][$key] = $form[$key];
       unset($form[$key]);
@@ -630,6 +647,15 @@ function _comment_driven_prop_in_depth(&
   }
 }
 
+// @per-module-discrimination
+function _comment_driven_disguise_exceptions() {
+  // this implies potential name clashes between node_form and comment_form values
+  // in fact, comment_upload clashes with core's upload on preview [#741544-8]
+  return array(
+    'attachments', // @per-module-discrimination: comment_upload
+  );
+}
+
 function _comment_driven_disguise($element) {
   // @TODO: every call to comment_driven_assertion_failed will be removed after alpha/beta stage 
   if (!is_array($element)) comment_driven_assertion_failed('something nasty is happening somewhere: !is_array($element)');
@@ -696,10 +722,10 @@ function _comment_driven_restore_ids(&$e
 }
 
 // only first level COMMENT_DRIVEN__DISGUISE_PREFIX prefixed values are desired
-function _comment_driven_extract_state_values($state_values) {
+function _comment_driven_extract_comment_state_values($state_values) {
   $values = array();
   foreach (array_keys($state_values) as $key) {
-    if (strpos($key, COMMENT_DRIVEN__DISGUISE_PREFIX) === 0) { 
+    if (strpos($key, COMMENT_DRIVEN__DISGUISE_PREFIX) === 0 || in_array($key, _comment_driven_disguise_exceptions())) { 
       $values[$key] = $state_values[$key];
     }
   }
@@ -707,11 +733,17 @@ function _comment_driven_extract_state_v
   return $values;
 }
 
+function _comment_driven_extract_node_state_values($state_values) {
+  foreach (_comment_driven_disguise_exceptions() as $key) {
+    unset($state_values[$key]);
+  }
+}
+
 function comment_driven_build_preview($form, &$form_state) {
   unset($form_state['submit_handlers']);
   $comment_form = _comment_driven_undisguise($form);
   $comment_form_state = $form_state; // copied
-  $comment_form_state['values'] = _comment_driven_extract_state_values($form_state['values']);
+  $comment_form_state['values'] = _comment_driven_extract_comment_state_values($form_state['values']);
   
   $comment_form = comment_form_add_preview($comment_form, $comment_form_state);
   // previews the comment
@@ -816,7 +848,7 @@ function comment_driven_validate($form, 
   }
   $comment_form = _comment_driven_undisguise($form['comment_driven']);
   $comment_form_state = $form_state; // copied
-  $comment_form_state['values'] = _comment_driven_extract_state_values($form_state['values']);
+  $comment_form_state['values'] = _comment_driven_extract_comment_state_values($form_state['values']);
   
   $validate_handlers = $comment_form['#validate'];
   if (!empty($validate_handlers)) {
@@ -837,7 +869,7 @@ function comment_driven_submit($form, &$
   
   $comment_form = _comment_driven_undisguise($form['comment_driven']);
   $comment_form_state = $form_state; // copied
-  $comment_form_state['values'] = _comment_driven_extract_state_values($form_state['values']);
+  $comment_form_state['values'] = _comment_driven_extract_comment_state_values($form_state['values']);
   
   $submit_handlers = $comment_form['#submit'];
   // @TODO: every call to comment_driven_assertion_failed will be removed after alpha/beta stage 
@@ -889,9 +921,12 @@ function comment_driven_submit($form, &$
     db_query($query, $cid, $old_vid, $new_vid, serialize($changes), serialize($diff_render), time());
     $did = db_last_insert_id('comment_driven_log', 'did');
     
+    // revome values of elements with "exclude from disguise" treatment
+    // (comment was already submitted, so it won't mind dropping them without restoring them back)
+    $form_state['values'] = _comment_driven_extract_node_state_values($form_state['values']);
     // only save if some value differs from its #default_value
     // otherwise it is just a comment
-    node_form_submit($form, $form_state);
+    node_form_submit($form, $ned_form_state);
     
     if ($node->revision) {
       $nid = $form_state['nid'];
=================================================
message: wrong varname & missing return => node_form not being saved
branch:  6.x-1.x
tags:    
node:    dc84c549ce094bc98b5c5a3c76422d2269897d3c
=================================================
diff -r c00df3de5b46 -r dc84c549ce09 comment_driven/comment_driven.module
--- comment_driven.module	Sat Mar 13 21:22:47 2010 -0500
+++ comment_driven.module	Sun Mar 14 00:47:32 2010 -0500
@@ -734,9 +734,11 @@ function _comment_driven_extract_comment
 }
 
 function _comment_driven_extract_node_state_values($state_values) {
+  // received by val
   foreach (_comment_driven_disguise_exceptions() as $key) {
     unset($state_values[$key]);
   }
+  return $state_values;
 }
 
 function comment_driven_build_preview($form, &$form_state) {
@@ -926,7 +928,7 @@ function comment_driven_submit($form, &$
     $form_state['values'] = _comment_driven_extract_node_state_values($form_state['values']);
     // only save if some value differs from its #default_value
     // otherwise it is just a comment
-    node_form_submit($form, $ned_form_state);
+    node_form_submit($form, $form_state);
     
     if ($node->revision) {
       $nid = $form_state['nid'];
/////////////////////////////////////////////////
generated with: drudiff comment_driven comment_driven 241 242 245 
/////////////////////////////////////////////////
